package tmi.li.txwthrsmall;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class ColorPickerDialog extends Dialog {
  private int colors[] = new int[4];

  //Getter to get color
  public int getColor(){
    return Color.argb(colors[3], colors[0], colors[1], colors[2]);
  }
  
  public String getColorHex() {
	  return Integer.toHexString(getColor());
  }

  //Empty method to add it until it will be replaced from parent view
  public View.OnClickListener onSaveClicked = new View.OnClickListener() {
    public void onClick(View v) {

    }
    };

    ///Constructor get and set all controls!
  public ColorPickerDialog(Context context) {
    super(context);
      this.setTitle("Select your color:");
          setContentView(R.layout.colordialog);

          SeekBar seek1 = (SeekBar)findViewById(R.id.SeekBar01);
          SeekBar seek2 = (SeekBar)findViewById(R.id.SeekBar02);
          SeekBar seek3 = (SeekBar)findViewById(R.id.SeekBar03);
          SeekBar seek4 = (SeekBar)findViewById(R.id.SeekBar04);
          seek1.setOnSeekBarChangeListener(mSaveOnClickListener);
          seek2.setOnSeekBarChangeListener(mSaveOnClickListener);
          seek3.setOnSeekBarChangeListener(mSaveOnClickListener);
          seek4.setOnSeekBarChangeListener(mSaveOnClickListener);
          colors[3] = 255;
          TextView text1 = (TextView)findViewById(R.id.TextView01);
          TextView text2 = (TextView)findViewById(R.id.TextView02);
          TextView text3 = (TextView)findViewById(R.id.TextView03);
          TextView text4 = (TextView)findViewById(R.id.TextView04);
          TextView text5 = (TextView)findViewById(R.id.TextView05);
          TextView text6 = (TextView)findViewById(R.id.TextView06);
          Button button = (Button)findViewById(R.id.Button01);
          button.setText("Save");


          text1.setText("Red");
          text2.setText("Green");
          text3.setText("Blue");
          text6.setText("Tranparency");
          text4.setText("Selected color:");
          text5.setText("");
          text5.setHeight(50);
  }

  private OnSeekBarChangeListener mSaveOnClickListener = new OnSeekBarChangeListener() {
    public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
      switch(seekBar.getId()){
      case R.id.SeekBar01:
          colors[0] = progress;
        break;
      case R.id.SeekBar02:
        colors[1] = progress;
        break;
      case R.id.SeekBar03:
        colors[2] = progress;
        break;
      case R.id.SeekBar04:
        colors[3] = progress;
        break;
      }
       TextView ColorView = (TextView)findViewById(R.id.TextView05);
       ColorView.setBackgroundColor(Color.argb(colors[3], colors[0], colors[1], colors[2]));
    }


    //Not implemented
    public void onStartTrackingTouch(SeekBar seekBar) {
      // TODO Auto-generated method stub

    }

    //Not implemented
    public void onStopTrackingTouch(SeekBar seekBar) {
      // TODO Auto-generated method stub

    }
   };

    //Override show to update button event
    @Override
    public void show(){
      Button button = (Button)findViewById(R.id.Button01);
        button.setOnClickListener((android.view.View.OnClickListener) onSaveClicked);
        super.show();
    }

}